package eerbaar.server;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import eerbaar.client.ctr.IGameController;
import eerbaar.client.ctr.IGameControllerFactory;
import eerbaar.elements.extension.ElementFactory;
import eerbaar.game.GameFactory;
import eerbaar.game.IGame;
import eerbaar.persona.IPersona;
import eerbaar.shared.service.ServiceFactory;

public class TestConsole {

    public static void main(String[] args) throws IOException {

        registerServices();

        InputStreamReader cin = new InputStreamReader(System.in);
        BufferedReader in = new BufferedReader(cin);

        for (;;) {

            System.out.println("Control string: \r");
            String controlString = in.readLine();
            if (controlString.equals("exit")) {
                break;
            }

            IGameControllerFactory factory = ServiceFactory
                    .getService(IGameControllerFactory.class);

            IGame game = GameFactory.createGame();
            game.getArea().addElement(ElementFactory.create("bone", 0, 0));
            game.getArea().addElement(ElementFactory.create("bone", 5, 0));
            IPersona pet = game.getPersona("pet");

            IGameController ctr = factory.create(pet, game);

            ctr.input(controlString);
        }

    }

    private static void registerServices() {
        new eerbaar.action.Module().registerServices();
        new eerbaar.action.lib.Module().registerServices();
        new eerbaar.expression.Module().registerServices();
        new eerbaar.expression.lib.Module().registerServices();

        new eerbaar.shared.message.Module().registerServices();
        new eerbaar.client.ctr.Module().registerServices();
        new eerbaar.collision.Module().registerServices();
    }

}
